﻿using System.Text.RegularExpressions;

namespace Common
{
    public static class HtmlFilter
    {
        /// <summary>
        /// 删除标签和脚本
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string NormalFilter(string input)
        {
            string str = Regex.Replace(input, @"<a[^>]*>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"<script[^>]*>", "", RegexOptions.IgnoreCase);
            str = str.Replace("</a>", "").Replace("</script>", "");
            return str;
        }

        public static string FilterHtml(string input)
        {
            string str = Regex.Replace(input, @"<[a-zA-Z0-1]+[^>]*>", "", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"</[a-zA-Z0-1]+>", "", RegexOptions.IgnoreCase);
            return str;
        }

        public static string GetSummary(string input)
        {
            string str = FilterHtml(input);
            if (str.Length > 200)
            {
                str = str.Substring(0, 199);
            }
            return str;
        }
    }
}